@using MudBlazor.Internal
@namespace MudBlazor
@inherits MudFormComponent<T, string>
@typeparam T


@code
{

    protected virtual RenderFragment InputContent =>
        @<MudTextField @ref="_inputReference" @attributes="UserAttributes" Label="@Label" @bind-Text="@Text" HelperText="@HelperText" HelperTextOnFocus="@HelperTextOnFocus" Variant="@Variant" ReadOnly="@(!Editable || ReadOnly)" T="string" Style="@Style"
                    @onclick="(() => { if (!Editable) ToggleState(); })" OnAdornmentClick="ToggleState" Disabled="@Disabled" Adornment="@Adornment"
                    AdornmentIcon="@AdornmentIcon" AdornmentColor="@AdornmentColor" IconSize="@IconSize" Margin="@Margin" Placeholder="@Placeholder"
                    Required="@Required" RequiredError="@RequiredError" Error="@Error" ErrorText="@ErrorText" @onkeydown="HandleKeyDown" />;

    protected virtual RenderFragment PickerContent => null;

    protected virtual RenderFragment Render =>
    @<CascadingValue Value="@this" IsFixed="true">
        <div class="@PickerClass" id="@_elementId">
            @if (PickerVariant != PickerVariant.Static)
            {
                <CascadingValue Name="Standalone" Value="false" IsFixed="true">
					@if(InputContent != null) {    
						@InputContent
					}
                </CascadingValue>
            }
            @if (IsOpen && PickerVariant == PickerVariant.Inline)
            {
				<MudPopover Open="IsOpen" Fixed="true" AnchorOrigin="Origin.TopLeft" TransformOrigin="Origin.TopLeft" OverflowBehavior="OverflowBehavior.FilpOnOpen" Paper="false">
				   <div @ref="_pickerInlineRef" class="@PickerInlineClass">
					   <MudPaper @attributes="UserAttributes" Class="@PickerPaperClass" Elevation="@_pickerElevation" Square="@_pickerSquare">
						   <div class="@PickerContainerClass">
							   @if(PickerContent != null){
								   @PickerContent
							   }
						   </div>
							@if (PickerActions != null)
							{
								<div class="@ActionClass">
									@PickerActions(this)
								</div>
							}
					   </MudPaper>
				   </div>
			   </MudPopover>
            }
            else if (PickerVariant == PickerVariant.Static)
            {
               <MudPaper @attributes="UserAttributes" Class="@PickerPaperClass" Elevation="@_pickerElevation" Square="@_pickerSquare">
                   <div class="@PickerContainerClass">
					   @if(PickerContent != null){
						   @PickerContent
					   }
                   </div>
                    @if (PickerActions != null)
                    {
                        <div class="@ActionClass">
                            @PickerActions(this)
                        </div>
                    }
               </MudPaper>
            }
            else if(IsOpen && PickerVariant == PickerVariant.Dialog)
            {
               <MudOverlay Visible="IsOpen" OnClick="CloseOverlay" DarkBackground="true" Class="mud-overlay-dialog">
                   <MudPaper @attributes="UserAttributes" Class="@PickerPaperClass" Elevation="@_pickerElevation" Square="@_pickerSquare">
                       <div class="@PickerContainerClass">
							@if(PickerContent != null){
								@PickerContent
							}
                       </div>
                        @if (PickerActions != null)
                        {
                            <div class="@ActionClass">
                                @PickerActions(this)
                            </div>
                        }
                   </MudPaper>
               </MudOverlay>
            }
        </div>
        @if (PickerVariant == PickerVariant.Inline)
        {
            <MudOverlay Visible="IsOpen" OnClick="CloseOverlay" LockScroll="false" />
        }
    </CascadingValue>;
}


